package internationalenergytradingplatform.controller.AdministratorsController;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import internationalenergytradingplatform.VO.SupplierPageQueryVO;
import internationalenergytradingplatform.context.BaseContext;

import internationalenergytradingplatform.dao.SupplierAccountDao;
import internationalenergytradingplatform.dao.SupplierAccountMapper;
import internationalenergytradingplatform.dto.SupplierPageQueryDTO;
import internationalenergytradingplatform.result.PageResult;
import internationalenergytradingplatform.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 名称AdministratorSupplierController
 * 描述
 *
 * @version 1.0
 * @author:DuanMM
 * @datatime:2024-03-28 20:32
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/administrator-supplier")
public class AdministratorSupplierController {

    @Autowired
    private SupplierAccountMapper supplierAccountMapper;
    @Autowired
    private SupplierAccountDao supplierAccountDao;
    /**
     * 根据tele分页查找供应商信息
     */
    @GetMapping("/paginationQuery")
    public Result<PageResult> pagingToQueryAllOrder(SupplierPageQueryDTO supplierPageQueryDTO) {

        PageHelper.startPage(supplierPageQueryDTO.getPage(), supplierPageQueryDTO.getPageSize());
        Page<SupplierPageQueryVO> page = supplierAccountMapper.supplierPageQuery(supplierPageQueryDTO);
        long total = page.getTotal();
        List<SupplierPageQueryVO> records = page.getResult();
        log.info("分页查询结果：{}", records);
        PageResult pageResult = new PageResult(total, records);
        return Result.success(pageResult);
    }

    @PutMapping("/updateSupplierAccountState")
    public Result<String> updateSupplierAccountState(String tele, Integer state) {
        int updatedCount = supplierAccountDao.updateSupplierAccountState(tele, state);
        if (updatedCount > 0) {
            return Result.success("供应商状态更新成功");
        } else {
            return Result.error("供应商状态更新失败");
        }
    }
}
